#include <iostream>

//https://www.nowcoder.com/practice/eebb2983b7bf40408a1360efb33f9e5d?tpId=40&&tqId=31013&rp=1&ru=/activity/oj&qru=/ta/kaoyan/question-ranking

using namespace std;

class Date {
public:
//构造函数
    Date(int year = 1900, int month = 1, int day = 1) {
        if (year < 1900 || month < 1 || month > 12 || day < 1 || day > GetMonthDay(year, month)) {
            cout << "非法日期" << endl;
        }
        _year = year;
        _month = month;
        _day = day;
    }
//拷贝构造
    Date(const Date &d) {
        _year = d._year;
        _month = d._month;
        _day = d._day;
    }
//析构函数
    ~Date() {
        _year = 0;
        _month = 0;
        _day = 0;
    }
//日期
    int GetMonthDay(int year, int month) {
        static int monthDayArray[13] = {31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))) {
            return 29;
        } else {
            return monthDayArray[month];
        }
    }

// +=
    Date& operator+=(int day) {
        _day += day;
        while (_day > GetMonthDay(_year, _month)) {
            _day -= GetMonthDay(_year, _month);
            _month++;
            if (_month > 12) {
                _year++;
                _month = 1;
            }
        }
        return *this;
    }
    void Print() {
        printf("%04d-%02d-%02d\n", _year, _month, _day);
    }
private:
    int _year;
    int _month;
    int _day;
};

int main() {
    int num = 0;
    int year = 0;
    int month = 0;
    int day = 0;
    int more = 0;
    cin >> num;
    for (int i = 0; i < num; ++i) {
        cin >> year >> month >> day >> more;
        Date A(year, month, day);
        A += more;
        A.Print();
    }
    return 0;
}


